package com.example.task1.ui.home.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.AllServiceBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class RecommendServiceAdapter extends BaseAdapter<AllServiceBean.RowsBean> {

    private Context context;
    private List<AllServiceBean.RowsBean> mData = new ArrayList<>();
    private ImageView ivImage;
    private TextView title;
    private HashMap<Integer,Class> map;

    public RecommendServiceAdapter(Context context) {
        this.context = context;
    }



    public void setDate(List<AllServiceBean.RowsBean> data, HashMap<Integer,Class> map) {
        int size = mData.size();
        this.mData.addAll(data);
        this.map = map;
        notifyItemInserted(size);
    }

    @Override
    protected void setData(List<AllServiceBean.RowsBean> rows) {

    }

    @Override
    protected int getLayout() {
        return R.layout.base_service;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<AllServiceBean.RowsBean> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, AllServiceBean.RowsBean date) {
        MyApplication.glide(ivImage,date.getImgUrl());
        title.setText(date.getServiceName());
        holder.itemView.setOnClickListener(v -> {
            Class aClass = map.get(date.getId());
            if (Objects.nonNull(aClass)) {
                boolean login = MyApplication.isLogin(context);
                if (login) {
                    return;
                }
                MyApplication.intent(context,aClass);
            }else {
                MyApplication.show("该模块还没有开发~");
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        ivImage = itemView.findViewById(R.id.iv_image);
        title = itemView.findViewById(R.id.title);
    }
}
